package org.ktpro.shortlink.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import org.ktpro.shortlink.admin.common.convention.result.Result;
import org.ktpro.shortlink.admin.remote.dto.ShortLinkFeignRemoteService;
import org.ktpro.shortlink.admin.remote.dto.req.ShortLinkGroupStatsReqDTO;
import org.ktpro.shortlink.admin.remote.dto.req.ShortLinkStatsAccessRecordGroupReqDTO;
import org.ktpro.shortlink.admin.remote.dto.req.ShortLinkStatsAccessRecordReqDTO;
import org.ktpro.shortlink.admin.remote.dto.req.ShortLinkStatsReqDTO;
import org.ktpro.shortlink.admin.remote.dto.resp.ShortLinkStatsAccessRecordRespDTO;
import org.ktpro.shortlink.admin.remote.dto.resp.ShortLinkStatsRespDTO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短链接监控服务控制层
 */
@RestController(value = "shortLinkStatsControllerByAdmin")
@RequiredArgsConstructor
public class ShortLinkStatsController {

    private final ShortLinkFeignRemoteService shortLinkFeignRemoteService;

    /**
     * 访问单个短链接指定时间内监控数据
     */
    @GetMapping("/api/short-link/admin/v1/stats")
    public Result<ShortLinkStatsRespDTO> shortLinkStats(ShortLinkStatsReqDTO requestParam) {
        return shortLinkFeignRemoteService.oneShortLinkStats(requestParam.getFullShortUrl(), requestParam.getGid()
                , requestParam.getStartDate(), requestParam.getEndDate());
    }

    /**
     * 指定时间内访问记录监控
     */
    @GetMapping("/api/short-link/admin/v1/stats/access-record")
    public Result<Page<ShortLinkStatsAccessRecordRespDTO>> shortLinkAccessRecordStats(ShortLinkStatsAccessRecordReqDTO requestParam) {
        return shortLinkFeignRemoteService.pageLinkStatsAccessRecord(
                requestParam.getFullShortUrl(),
                requestParam.getGid(),
                requestParam.getStartDate(),
                requestParam.getEndDate(),
                requestParam.getEnableStatus(),
                requestParam.getCurrent(),
                requestParam.getSize());
    }

    /**
     * 指定时间内分组内所有短链接的监控记录统计
     */
    @GetMapping("/api/short-link/admin/v1/stats/group")
    public Result<ShortLinkStatsRespDTO> shortLinkStatsGroup(ShortLinkGroupStatsReqDTO requestParam) {
        return shortLinkFeignRemoteService.groupShortLinkStats(requestParam.getGid(),
                requestParam.getStartDate(), requestParam.getEndDate());
    }

    /**
     * 指定时间内分组访问记录监控
     */
    @GetMapping("/api/short-link/admin/v1/stats/access-record/group")
    public Result<Page<ShortLinkStatsAccessRecordRespDTO>> shortLinkAccessRecordStatsByGroup(ShortLinkStatsAccessRecordGroupReqDTO requestParam) {
        return shortLinkFeignRemoteService.pageLinkStatsAccessRecordByGroup(requestParam.getGid(), requestParam.getStartDate(), requestParam.getEndDate(), requestParam.getCurrent(), requestParam.getSize());
    }
}
